package com.qckj.amz.controller;

import com.obs.services.ObsClient;
import com.obs.services.model.ObjectListing;
import com.obs.services.model.PutObjectResult;
import com.qckj.amz.domain.ProductImage;
import com.qckj.amz.service.IProductImageService;
import com.qckj.amz.service.UploadService;
import com.qckj.common.annotation.Log;
import com.qckj.common.config.QckjConfig;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.enums.BusinessType;
import com.qckj.common.utils.DateUtils;
import com.qckj.common.utils.SecurityUtils;
import com.qckj.common.utils.file.FileMediaTypeUtils;
import com.qckj.common.utils.file.FileUploadUtils;
import com.qckj.framework.config.ServerConfig;
import com.qckj.system.service.ISysConfigService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;
import java.util.Date;

/**
 * 上传文件 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("/amz/upload")
@Api(tags = "上传文件")
public class UploadController {

    @Autowired
    public UploadService uploadService;

    /**
     * 通用上传请求--多参数上传
     * @param multipart         图片信息
     * @param businesstModel    业务模块： 用户user,商品product,微信wechat,news文章
     * @param pid               分类ID 0编辑器,1商品图片,2拼团图片,3砍价图片,4秒杀图片,5文章图片,6组合数据图,7前台用户,8微信系列
     * @return
     * @throws Exception
     */
    @Log(title = "上传", businessType = BusinessType.UPLOAD)
    @PostMapping("/image")
    public AjaxResult image(MultipartFile multipart, String businesstModel, Long pid) throws Exception {

        AjaxResult ajaxResult = uploadService.imageUpload(multipart, businesstModel, pid);

        return ajaxResult;
    }


    /**
     * 上传网络图片
     * @param businesstModel    业务模块： 用户user,商品product,微信wechat,news文章
     * @param pid               分类ID 0编辑器,1商品图片,2拼团图片,3砍价图片,4秒杀图片,5文章图片,6组合数据图,7前台用户,8微信系列
     * @param pathName          图片路径（可拼接）
     * @param splitChar         分隔符
     * @return
     */
    @Log(title = "上传网络图片-提交", businessType = BusinessType.UPLOAD)
    @PostMapping("/uploadNetworkPictures")
    public AjaxResult uploadNetworkPictures(
            @RequestParam(name = "businesstModel") String businesstModel,
            @RequestParam(name = "pid") Long pid,
            @RequestParam(name = "pathName") String pathName,
            @RequestParam(name = "splitChar") String splitChar) {

        AjaxResult res = uploadService.uploadNetworkPictures(businesstModel,pid,pathName,splitChar);

        return res;
    }


}



